package com.aaa.power.controller;

import com.aaa.common.constants.ReturnCode;
import com.aaa.common.util.Result;
import com.aaa.power.entity.User;
import com.aaa.power.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 用户信息表(User)表控制层
 *
 * @author makejava
 * @since 2020-11-13 09:33:15
 */
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;

    /**
     * 通过主键查询单条数据
     *
     * @param userId 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public Result selectOne(Integer userId) {
        return new Result(ReturnCode.SUCCESSS.getCode(),
                ReturnCode.SUCCESSS.getMsg(),this.userService.queryById(userId));
    }

    /**
     * 分页加各种条件查询
     * @param pageNo
     * @param pageSize
     * @param user
     * @return
     */
    @GetMapping("queryPageByParam")
    public Result queryPageByParam(Integer pageNo, Integer pageSize, User user){
        return userService.queryPageByParam(pageNo,pageSize,user);
    }

    @GetMapping("insertOrUpdate")
    public Result insertOrUpdate(User user){
        System.out.println(user.getUserId()+" "+user.getUserName());
        return userService.insertOrUpdate(user);
    }

    @GetMapping("deleteById")
    public Result deleteById(Integer userId){
        return userService.deleteById(userId);
    }

    @GetMapping("update")
    public Result update(User User){
        return userService.update(User);
    }


    /**
     * 通过用户名查询
     * @param userName
     * @return
     */
    @GetMapping("queryUserByParam")
    public User queryUserByParam(@RequestParam("userName") String userName){
        return this.userService.queryUserByParam(userName);
    }
}